//
//  WriteWeiboViewController.m
//  WeiboAD
//
//  Created by liu guoqiang on 16/7/22.
//  Copyright © 2016年 com.liu.weiboAD. All rights reserved.
//

#import "WriteWeiboViewController.h"

@interface WriteWeiboViewController ()
@property(nonatomic,strong)UIBarButtonItem *cancelBarButoonItem;
@property(nonatomic,strong)UIBarButtonItem *sendBarButoonItem;
@property (weak, nonatomic) IBOutlet UITextView *contentTextView;
@end

@implementation WriteWeiboViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"发微博";
    self.navigationItem.leftBarButtonItem = self.cancelBarButoonItem;
    self.navigationItem.rightBarButtonItem = self.sendBarButoonItem;
}

-(void)sendWeiboWithUser:(NSDictionary *)dic{
    XCHTTPManager *manager = [XCHTTPManager shareManager];
    NSString *url = [NSString stringWithFormat:@"%@",ApisendWeibo];
    NSLog(@"url:%@",url);
    [manager post:url params:dic success:^(id responseObj) {
      [MBProgressHUD showSuccess:@"成功发送微博"];
    } failured:^(NSError *error) {
        [MBProgressHUD showError:@"请求失败"];
    }];
    
}



-(UIBarButtonItem *)cancelBarButoonItem{
    if (_cancelBarButoonItem == nil) {
        _cancelBarButoonItem = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancel)];
    }
    return _cancelBarButoonItem;
}

-(void)cancel{
    self.contentTextView.text = @"";
}

-(UIBarButtonItem *)sendBarButoonItem{
    if (_sendBarButoonItem == nil) {
        _sendBarButoonItem = [[UIBarButtonItem alloc]initWithTitle:@"发送" style:UIBarButtonItemStylePlain target:self action:@selector(send)];
    }
    return _sendBarButoonItem;
}

-(void)send{
    if ([UserDefault getValueOfKey:@"access_token"]) {
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        dic[@"access_token"] = [UserDefault getValueOfKey:@"access_token"];
        dic[@"status"] = self.contentTextView.text;
        [self sendWeiboWithUser:dic];
    }else{
        [MBProgressHUD showError:@"无效token"];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
